import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { registerApplication, start } from 'single-spa'
async function loadScript(url) {
  return new Promise((resolve, reject) => {
      let script = document.createElement('script');
      script.src = url;
      script.onload = resolve;
      script.onerror = reject;
      document.head.appendChild(script);
  }) 
}
registerApplication('app1',
  async () => {
      console.log('加载模块')
      await loadScript(`http://localhost:8081/js/chunk-vendors.js`)
      await loadScript(`http://localhost:8081/js/app.js`)
      return window.app1; 
  },
  location => location.pathname.startsWith('/app1')  
)
registerApplication('app2',
  async () => {
      console.log('加载模块')
      await loadScript(`http://localhost:8082/js/chunk-vendors.js`)
      await loadScript(`http://localhost:8082/js/app.js`)
      return window.app2; 
  },
  location => location.pathname.startsWith('/app2')  
)
start();

createApp(App).use(router).mount('#app')
